package com.ruoyi.zzw.service.impl;

import java.util.List;

import com.ruoyi.zzw.domain.EventTrack;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.zzw.mapper.EventManageMapper;
import com.ruoyi.zzw.domain.EventManage;
import com.ruoyi.zzw.service.TEventManageService;

/**
 * 事件管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-12-06
 */
@Service
public class EventManageServiceImpl implements TEventManageService
{
    @Autowired
    private EventManageMapper eventManageMapper;

    /**
     * 查询事件管理
     * 
     * @param cEventId 事件管理主键
     * @return 事件管理
     */
    @Override
    public EventManage selectTEventManageByCEventId(Long cEventId)
    {
        return eventManageMapper.selectTEventManageByCEventId(cEventId);
    }

    /**
     * 查询事件管理列表
     * 
     * @param eventManage 事件管理
     * @return 事件管理
     */
    @Override
    public List<EventManage> selectTEventManageList(EventManage eventManage)
    {
        return eventManageMapper.selectTEventManageList(eventManage);
    }

    /**
     * 新增事件管理
     * 
     * @param eventManage 事件管理
     * @return 结果
     */
    @Transactional
    @Override
    public int insertTEventManage(EventManage eventManage)
    {
        int rows = eventManageMapper.insertTEventManage(eventManage);
        insertTEventTrack(eventManage);
        return rows;
    }

    /**
     * 修改事件管理
     * 
     * @param eventManage 事件管理
     * @return 结果
     */
    @Transactional
    @Override
    public int updateTEventManage(EventManage eventManage)
    {
        eventManageMapper.deleteTEventTrackByCEventId(eventManage.getcEventId());
        insertTEventTrack(eventManage);
        return eventManageMapper.updateTEventManage(eventManage);
    }

    /**
     * 批量删除事件管理
     * 
     * @param cEventIds 需要删除的事件管理主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteTEventManageByCEventIds(Long[] cEventIds)
    {
        eventManageMapper.deleteTEventTrackByCEventIds(cEventIds);
        return eventManageMapper.deleteTEventManageByCEventIds(cEventIds);
    }

    /**
     * 删除事件管理信息
     * 
     * @param cEventId 事件管理主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteTEventManageByCEventId(Long cEventId)
    {
        eventManageMapper.deleteTEventTrackByCEventId(cEventId);
        return eventManageMapper.deleteTEventManageByCEventId(cEventId);
    }

    /**
     * 新增事件跟踪信息
     * 
     * @param eventManage 事件管理对象
     */
    public void insertTEventTrack(EventManage eventManage)
    {
        List<EventTrack> eventTrackList = eventManage.getTEventTrackList();
        Long cEventId = eventManage.getcEventId();
        if (StringUtils.isNotNull(eventTrackList))
        {
            List<EventTrack> list = new ArrayList<EventTrack>();
            for (EventTrack eventTrack : eventTrackList)
            {
                eventTrack.getcEventId();
                list.add(eventTrack);
            }
            if (list.size() > 0)
            {
                eventManageMapper.batchTEventTrack(list);
            }
        }
    }
}
